package com.lcf.app.rabbitmq.provider.config;

import com.lcf.common.model.MqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ChenFei
 * @date 2021/12/2
 */
@Configuration
public class RabbitDirectConfig {

    @Bean
    public Queue directQueueOne() {
        return QueueBuilder.durable(MqConstant.DIRECT_QUEUE_ONE).build();
    }

    @Bean
    public Queue directQueueTwo() {
        return QueueBuilder.durable(MqConstant.DIRECT_QUEUE_TWO).build();
    }

    // 准备一个交换机
    @Bean
    public DirectExchange directExchange() {
        return ExchangeBuilder.directExchange(MqConstant.DIRECT_EXCHANGE).build();
    }

    // 将交换机和队列进行绑定
    @Bean
    public Binding bindingDirectOne() {
        return BindingBuilder.bind(directQueueOne()).to(directExchange()).with(MqConstant.DIRECT_KEY_ONE);
    }

    @Bean
    public Binding bindingDirectTwo() {
        return BindingBuilder.bind(directQueueTwo()).to(directExchange()).with(MqConstant.DIRECT_KEY_TWO);
    }

}
